//项目路径
var project = 'http://localhost/website';

//新闻列表页类目
function listCategory(cid, csid) {
    //**************类目******************/
    $.ajax({
        url: project + '/category/findAllCategories',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            //***************面包屑******************************
            for (var i = 0; i < data.length; i++) {
                var type = data[i].type == 0 ? "products" : "news";

                if (cid != "" && cid == data[i].id) {
                    $("#breadCrumb").append(
                        ` <li><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
                    );
                    break;
                }
                if (csid != "") {
                    for (var j = 0; j < data[i].list.length; j++) {
                        if (data[i].list[j].id == csid) {
                            cid = data[i].id;
                            $("#breadCrumb").append(
                                ` <li><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
                            );
                            $("#breadCrumb").append(
                                `<li><a href="/website/` + type + `.html?csid=` + data[i].list[j].id + `">` + data[i].list[j].csname + `</a></li>`
                            );
                            break;
                        }
                    }
                }
            }
            //************我们的成果*****************************
            for (var i = 0; i < data.length; i++) {
                var style="color: #fff;background-color: #000";
                if (cid == data[i].id) {
                    type = data[i].type == 0 ? "products" : "news";
                    $("#categorySecond").append(`<a class="tlist"  href="/website/` + type + `.html?cid=` + data[i].id + `" style="`+(csid==""?style:"")+`">全部</a>`);
                    for (var j = 0; j < data[i].list.length; j++) {
                        $("#categorySecond").append(`   <a class="tlist" href="/website/` + type + `.html?csid=` + data[i].list[j].id + `" style="`+(data[i].list[j].id==csid?style:"")+`">` + data[i].list[j].csname + `</a>`);
                    }
                    $("#categorySecond").append(`<div class="both"></div>`);
                }
            }
            //**************类目nav******************************

            //首页
            $("#category").append(
                `<li class="` + (cid == 0 ? "active" : "") + `"><a href="index.html">首页 <span class="sr-only">(current)</span></a></li>`
            );
            //类目
            for (var i = 0; i < data.length; i++) {
                var type = data[i].type == 0 ? "products" : "news";
                $("#category").append(
                    `<li class="` + (cid == data[i].id ? "active" : "") + `"><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
                );
            }
            //关于我们
            $("#category").append(
                `<li  class="` + (cid == -1 ? "active" : "") + `"><a href="about.html">关于我们</a></li>`
            );
        }
    });
}

//产品列表页类目
function listCategoryForProduct(cid, csid) {
    //**************类目******************/
    $.ajax({
        url: project + '/category/findAllCategories',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            //***************面包屑******************************
            for (var i = 0; i < data.length; i++) {
                var type = data[i].type == 0 ? "products" : "news";
                var str = data[i].type == 0 ? "class='tit'" : "";

                if (cid != "" && cid == data[i].id) {
                    $(".mianbaoxue").append(
                        ` /<a `+str+`href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a>`
                    );
                    break;
                }
                if (csid != "") {
                    for (var j = 0; j < data[i].list.length; j++) {
                        if (data[i].list[j].id == csid) {
                            cid = data[i].id;
                            $(".mianbaoxue").append(
                                ` /<a `+str+` href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a>`
                            );
                            $(".mianbaoxue").append(
                                `/<a `+str+` href="/website/` + type + `.html?csid=` + data[i].list[j].id + `">` + data[i].list[j].csname + `</a>`
                            );
                            break;
                        }
                    }
                }
            }
            //************我们的成果*****************************

            for (var i = 0; i < data.length; i++) {
                if (cid == data[i].id) {
                    type = data[i].type == 0 ? "products" : "news";
                    if (csid == "") {
                        $("#categorySecond").append(` <a class="linka  on  " href="/website/` + type + `.html?cid=`+cid+`">全部</a>`);
                    } else {
                        $("#categorySecond").append(` <a class="linka" href="/website/` + type + `.html?cid=`+cid+`">全部</a>`);
                    }
                    for (var j = 0; j < data[i].list.length; j++) {
                        var blackColor = "linka";
                        if (csid == data[i].list[j].id) {
                            blackColor = "linka  on"
                        }
                        $("#categorySecond").append(`<a class="` + blackColor + `"  href="/website/` + type + `.html?csid=` + data[i].list[j].id + `">` + data[i].list[j].csname + `</a>`);
                    }
                }
            }
            //**************类目nav******************************

            //首页
            $("#category").append(
                `<li class="` + (cid == 0 ? "active" : "") + `"><a href="index.html">首页 <span class="sr-only">(current)</span></a></li>`
            );
            //类目
            for (var i = 0; i < data.length; i++) {
                var type = data[i].type == 0 ? "products" : "news";
                $("#category").append(
                    `<li class="` + (cid == data[i].id ? "active" : "") + `"><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
                );
            }
            //关于我们
            $("#category").append(
                `<li  class="` + (cid == -1 ? "active" : "") + `"><a href="about.html">关于我们</a></li>`
            );
        }
    });
}

//详情页类目
function detailCategory(csid) {
    //**************类目******************/
    $.ajax({
        url: project + '/category/findAllCategories',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            var cid = 0;
            //面包屑
            for (var i = 0; i < data.length; i++) {
                for (var j = 0; j < data[i].list.length; j++) {

                    if (data[i].list[j].id == csid) {
                        var type = data[i].type == 0 ? "products" : "news";
                        cid = data[i].id;
                        $("#breadCrumb").html(
                            ` <a href="index.html">首页</a> / <a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a> / <a href="/website/` + type + `.html?csid=` + data[i].list[j].id + `">` + data[i].list[j].csname + `</a>`
                        );
                        break;
                    }
                }
            }
            //首页
            $("#category").append(
                `<li class="` + (cid == 0 ? "active" : "") + `"><a href="index.html">首页 <span class="sr-only">(current)</span></a></li>`
            );
            //类目
            for (var i = 0; i < data.length; i++) {
                var type = data[i].type == 0 ? "products" : "news";
                $("#category").append(
                    `<li class="` + (cid == data[i].id ? "active" : "") + `"><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
                );
            }
            //关于我们
            $("#category").append(
                `<li  class="` + (cid == -1 ? "active" : "") + `"><a href="about.html">关于我们</a></li>`
            );
        }
    });
}

//获取一级二级类目集合数据
function getCategory(){
    var value="";
    $.ajax({
        url: project + '/category/findAllCategories',
        dataType: 'json',
        async:false,
        type: 'get',
        success: function (data) {
            value=data;
        }
    });
    return value;
}

//类目nav
function categoryNav(cid,data) {
    //首页
    $("#category").append(
        `<li class="` + (cid == 0 ? "active" : "") + `"><a href="index.html">首页 <span class="sr-only">(current)</span></a></li>`
    );
    //类目
    for (var i = 0; i < data.length; i++) {
        var type = data[i].type == 0 ? "products" : "news";
        $("#category").append(
            `<li class="` + (cid == data[i].id ? "active" : "") + `"><a href="/website/` + type + `.html?cid=` + data[i].id + `">` + data[i].cname + `</a></li>`
        );
    }
    //关于我们
    $("#category").append(
        `<li  class="` + (cid == -1 ? "active" : "") + `"><a href="about.html">关于我们</a></li>`
    );
}